<?php

namespace Proyecto\MainBundle\EventListener;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;

class InfoViewListener
{
    private $container;
    
    public function __construct(ContainerInterface $container){
        $this->container=$container;
    }
    
   public function onKernelView(GetResponseForControllerResultEvent $response)
    {
       $result=$response->getControllerResult();
        $security = $this->container->get('security.context');
        if ($security->isGranted('IS_AUTHENTICATED_FULLY')){
            $result['perfil'] = $security->getToken()->getUser()->getPerfil()->getPerfil();
            $user = $security->getToken()->getUser()->getUsuario();
        }
        else{
            $result['perfil'] = 'visitante';
            $user = 'Visitante';
        }
        $configurador = $this->container->get('configurador');
        $route=$response->getRequest()->get('_route');
        //echo $route;
        $result['titulo']=$configurador->getTitulo($route,$user);
        $result['header']=$configurador->getHeader($route,$user);
        $result['footer']=$configurador->getFooter($route,$user);
        $response->setControllerResult($result);
    }
}
